/*
 * @Description: 撤销弹窗
 * @Author: Zzt
 * @Date: 2023-02-20 21:26:03
 * @LastEditTime: 2023-02-28 16:14:50
 */
import { cancelAnnouncement } from '@/api/announcement/announcement';
import JPModal from '@/components/JPComponents/JPModal';
import { ICommonDialog } from '@/interfaces/global';
import { Button, Form, Input } from 'antd';
import { useAnnouncementMgtContext } from '../../contexts/AnnouncementMgtContext';

interface IEditAnnounce extends ICommonDialog {
  withdrawData: any;
}
const Withdraw = (props: IEditAnnounce) => {
  const { editStatus } = useAnnouncementMgtContext();
  const { visible, onClose, withdrawData } = props;
  const [form] = Form.useForm();

  const onFinish = (values: {}) => {
    cancelAnnouncement({ id: withdrawData.id, ...values }).then((res) => {
      const { data } = res;
      editStatus(data);
      onClose();
    });
    console.log('withdraw', values);
  };
  return (
    <>
      <JPModal
        draggable={true}
        visible={visible}
        onCancel={onClose}
        title="撤销"
        footer={[
          <Button key={'cancel'} onClick={onClose}>
            取消
          </Button>,
          <Button type="primary" key={'finish'} onClick={() => form.submit()}>
            确定
          </Button>
        ]}
      >
        <Form form={form} onFinish={onFinish}>
          <Form.Item label="取消发布原因" rules={[{ required: true }]} name="reason">
            <Input.TextArea placeholder="请填写取消发布原因"></Input.TextArea>
          </Form.Item>
        </Form>
      </JPModal>
    </>
  );
};
export default Withdraw;
